#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=205,M=2010;
int a[M],b[M],f[N][N];
int w[M];
int main()
{
    memset(f,0x3f,sizeof(f));
    f[0][0]=0;
    int aa,bb,n;
    cin>>aa>>bb>>n;
    for(int i=1;i<=n;i++) cin>>a[i]>>b[i]>>w[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=aa;j>=0;j--)
        {
            for(int k=bb;k>=0;k--)
            {
                f[j][k]=min(f[j][k],f[max(j-a[i],0)][max(k-b[i],0)]+w[i]);
            }
        }
    }
    cout<<f[aa][bb];

    return 0;
}

